<?php
	class Landingurl extends Model_Abstract{
		
		public function add($url){
			try
			{
				$sql = 'insert into landing_urls set  url=?';
				$result = $this->_connection->execute($sql, array($url), true);
				return $result;
			}
			catch (Exception $e)
			{
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function delete($id){
			try
			{
				$sql = 'delete from landing_urls where id=?';
				$result = $this->_connection->execute($sql, array($id));
				return $result;
			}
			catch (Exception $e)
			{
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function update($url, $id){
			try
			{
				$sql = 'update landing_urls set  url=? where id=?';
				$result = $this->_connection->execute($sql, array($url, $id));
				return $result;
			}
			catch (Exception $e)
			{
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function getAllLandingUrls(){
			try
			{
				$sql = 'select * from landing_urls';
				$result = $this->_connection->query($sql);
				return $result;
			}
			catch (Exception $e)
			{
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
		public function getLandingUrlById($id){
			try{
				$sql = 'select * from landing_urls where id=? limit 1';
				$result = $this->_connection->query($sql, array($id));
				if($result)
					return $result[0];
				return false;
			}catch (Exception $e)
			{
				QLog::log(__CLASS__.' '.__METHOD__.' --- '.$e->getMessage(), QLog::ERR);
				throw new Model_Exception($e->getMessage(), $e->getCode());
			}
		}
		
	}